package com.baizhi.controller;

import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/showPage")
    public @ResponseBody Map showPage(Integer page, Integer limit, @RequestParam(value = "option",defaultValue = "userName") String option, @RequestParam(value = "search",defaultValue = "") String search){
        Map map = userService.selectPage(page, limit, option, search);
        return map;
    }
    @RequestMapping("/updateStatus")
    public @ResponseBody Map updateStatus(Integer id){
        System.out.println("id = " + id);
        User user = userService.selectById(id);
        System.out.println("user = " + user);
        Map map = userService.updateUserStatus(user);
        return map;
    }
    @RequestMapping("/showAllCount")
    public @ResponseBody Map manCount(){
        long start = System.currentTimeMillis();
        Map map = null;
        try {
            map = userService.selectAllCountByThread();
        } catch (Exception e) {
            e.printStackTrace();
        }
        long m = System.currentTimeMillis()-start;
        System.out.println("间隔时间 = " + m+" ms");
        return map;
    }
}
